import 'package:eleapp/res/strings.dart';
import 'package:get/get.dart';
// 用户控制器
import './controller/usercontroller.dart';
// 引入本地缓存
import './localstorage/storage.dart';
import 'package:shared_preferences/shared_preferences.dart';

class InitClass {
  static Future<void> startInit() async {
    // 初始化本地缓存实例
    Store store = await Store.getInstance();
    bool islogin = await store.getBoolStatus(StringStyles.islogin);
    Map user = store.getMap(StringStyles.userInfo);
    int? userId = await store.getInt(StringStyles.userId);
    String? userAccount = await store.getString(StringStyles.userAccount);

    // print(islogin);
    // print(user);
    // print(userId);
    // print(userAccount);

    // 必须单独引入 不能依靠全局binding
    UserController userController = Get.put(UserController());

    userController.islogin.value = islogin;
    userController.user.value = user;
    userController.userId.value = userId ?? 0;
    userController.userAccount.value = userAccount ?? '';

    // 初始化基础缓存依赖实例
    await Get.putAsync(() => SharedPreferences.getInstance());
  }
}
